package org.apache.lorry.kafka.timerWheel;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.lorry.data.Date;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@Slf4j
public class SystemTimerDemo {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        SystemTimer systemTimer = new SystemTimer("timingWheel");

        long addMs = System.currentTimeMillis();
        systemTimer.add(new TimerTask(838) {
            @Override
            public void run() {
                long now = System.currentTimeMillis();
                log.info("time :{}", new Date());
                log.info("hello world cost :{}", (now - addMs));
            }
        });

        while (true) {
            try {
                systemTimer.advanceClock(1);
            } catch (Exception e) {
                log.error("advanceClock", e);
            }
        }
    }

}